package io.gitee.kotle.android.library.crash

import android.os.Process
import io.gitee.kotle.android.BaseGlobalConst.app
import io.gitee.kotle.android.utils.doOnlyDebug

/**
 * 全局异常捕获
 */
object CrashHelper : Thread.UncaughtExceptionHandler {

    override fun uncaughtException(t: Thread, e: Throwable) {
        UncaughtExceptionFragment.start(app, t, e)
        Process.killProcess(Process.myPid())
        System.exit(-1)
    }

    fun initCrash() {
        doOnlyDebug {
            Thread.setDefaultUncaughtExceptionHandler(CrashHelper)
        }
    }
}